package NG::Sys::Cached::DBColumnAny;
use strict;
use warnings;
use utf8;

use base 'NG::Sys::Cached::DBColumn';

sub make_fields {
	return 1;
}
sub check_field {
	return 1;
}
sub check_fields_ary {
	my ($self,$keys) = @_;
	return @$keys;
}
sub init {
	my ($self) = @_;
	$self->SUPER::init;
	$self->{sth}{delete} = $self->{dbh}->prepare("delete from `$self->{table}` where `$self->{pkey}`=? and `$self->{nkey}`=?");
}

sub _update_source {
	my ($self,$id,$data,$keys) = @_;
	unless($keys or @$keys){
		return 0;
	}
	my $sthu = $self->{sth}{update};
	my $sthd = $self->{sth}{delete};
	my @nkeys;
	my $blob = $self->{blob};
	for my $key(@$keys){
		if(defined (my $v = $data->{$key})){
			$sthu->execute($id,$key,$blob && ref $v ? encode_json($v) : $v);
			push @nkeys,$key;
		}else{
			$sthd->execute($id,$key);
		}
	}
	return \@nkeys;
}

1;
